package com.ruoyi.life.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.life.service.IFeSuretyService;
import com.ruoyi.omp.api.domain.FeSurety;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 企业保证金Controller
 *
 * @author Felix
 * @date 2021-12-27
 */
@Api(tags = " 企业保证金")
@RestController
@RequestMapping("/feSurety")
public class FeSuretyController extends BaseController {
    @Autowired
    private IFeSuretyService feSuretyService;

    /**
     * 查询企业保证金列表
     */
    @ApiOperation(value="查询企业保证金列表", notes="查询企业保证金列表")
    @PreAuthorize(hasPermi = "life:feSurety:list")
    @GetMapping("/list")
    public TableDataInfo list(FeSurety feSurety) {
        startPage();
        List<FeSurety> list = feSuretyService.selectFeSuretyList(feSurety);
        return getDataTable(list);
    }

    /**
     * 导出企业保证金列表
     */
    @ApiOperation(value="导出企业保证金列表", notes="导出企业保证金列表")
    @PreAuthorize(hasPermi = "life:feSurety:export")
    @Log(title = "企业保证金", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FeSurety feSurety) throws IOException {
        List<FeSurety> list = feSuretyService.selectFeSuretyList(feSurety);
        ExcelUtil<FeSurety> util = new ExcelUtil<FeSurety>(FeSurety.class);
        util.exportExcel(response, list, "企业保证金数据");
    }
    /**
     * 获取企业保证金详细信息
     */
    @ApiOperation(value="获取企业保证金详细信息", notes="获取企业保证金详细信息")
    @PreAuthorize(hasPermi = "life:feSurety:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(feSuretyService.selectFeSuretyById(id));
    }




    /**
     * 新增保证金记录(后台调用）
     */
    @PostMapping("/add")
    public R addSurety(@RequestBody FeSurety feSurety) {
        return toR(feSuretyService.insertFeSurety(feSurety));
    }
    /**
     * 新增企业保证金
     */
    @ApiOperation(value="新增企业保证金", notes="新增企业保证金")
    @PreAuthorize(hasPermi = "life:feSurety:add")
    @Log(title = "企业保证金", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FeSurety feSurety) {
        return toAjax(feSuretyService.insertFeSurety(feSurety));
    }

    /**
     * 修改企业保证金
     */
    @ApiOperation(value="修改企业保证金", notes="修改企业保证金")
    @PreAuthorize(hasPermi = "life:feSurety:edit")
    @Log(title = "企业保证金", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FeSurety feSurety) {
        return toAjax(feSuretyService.updateFeSurety(feSurety));
    }

    /**
     * 删除企业保证金
     */
    @ApiOperation(value="删除企业保证金", notes="删除企业保证金")
    @ApiImplicitParam(name = "ids", value = "企业保证金ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "life:feSurety:remove")
    @Log(title = "企业保证金", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(feSuretyService.deleteFeSuretyByIds(ids));
    }
}
